﻿using Mall.Infrastructure.Model;
using Mall.Infrastructure.Repository;
using Sx.Mall.Domain;
using Sx.Mall.WebContract.Dto;
using Sx.Mall.WebContract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sx.Mall.WebService
{
    public class LoginService : ILoginService
    {
       private readonly AppDomain app = AppDomain.CurrentDomain;

       /// <summary>
       /// 人员登陆
       /// </summary>
       /// <param name="accout"></param>
       /// <param name="password"></param>
       /// <returns></returns>
       public CommonResult<LoginUser> Login(string accout, string password)
       {
           CommonResult<LoginUser> result = new CommonResult<LoginUser>();
           using (IRepositoryContext ctx = app.GetRepositoryContext())
           {
               var userRepository = ctx.GetRepository<MallManager>();
               var item = MallManager.Login(userRepository, accout, password);
               result.IsResult = item.IsResult;
               result.Message = item.Message;
               if (result.IsResult)
               {
                   result.Result = new LoginUser();
                   result.Result.UserId = item.Result.UserID;
                   result.Result.UserName = item.Result.UserName;
               }
               ctx.Commit();
           }
           return result;
       }
    }

}
